package yxy.game.pm2.command.plainsCraft;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.PlainsCraftMessage;
import yxy.game.pm2.module.plainsCraft.PlainsCraftHandle;

import java.util.Date;

/** 中原争霸 中原争霸挑战 */
@MessageType(proto = Command.PlainsCraftChanllenge, classtype = PlainsCraftMessage.PlainsCraftChanllengeRequest.class)
public class CMD_PlainsCraftChanllenge extends Command<PlainsCraftMessage.PlainsCraftChanllengeRequest> {

	@Override
	public void execute(MessageSource messageSource, PlainsCraftMessage.PlainsCraftChanllengeRequest request) {
		try {
			Date date = new Date();
			String playerCode = messageSource.getTag();
			int rank = request.getRank();
			boolean skip = request.getSkip();

			PlainsCraftMessage.PlainsCraftChanllengeResponse.Builder response = PlainsCraftMessage.PlainsCraftChanllengeResponse.newBuilder();

			Result result = new PlainsCraftHandle().battleResponseExecute(playerCode, rank, skip, response);

			send(messageSource, response, result);

			Date date1 = new Date();
			System.out.println("PlainsCraftChanllenge:" + (date1.getTime() - date.getTime()));

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void send(MessageSource messageSource, PlainsCraftMessage.PlainsCraftChanllengeResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}